package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.UsageRecords;
import com.ruoyi.system.service.IUsageRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 备件使用记录管理Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/records2")
public class UsageRecordsController extends BaseController {
    @Autowired
    private IUsageRecordsService usageRecordsService;

    /**
     * 查询备件使用记录管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:records2:list')")
    @GetMapping("/list")
    public TableDataInfo list(UsageRecords usageRecords) {
        startPage();
        List<UsageRecords> list = usageRecordsService.selectUsageRecordsList(usageRecords);
        return getDataTable(list);
    }

    /**
     * 导出备件使用记录管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:records2:export')")
    //@Log(title= "备件使用记录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UsageRecords usageRecords) {
        List<UsageRecords> list = usageRecordsService.selectUsageRecordsList(usageRecords);
        ExcelUtil<UsageRecords> util = new ExcelUtil<UsageRecords>(UsageRecords.class);
        util.exportExcel(response, list, "备件使用记录管理数据");
    }

    /**
     * 获取备件使用记录管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:records2:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId) {
        return success(usageRecordsService.selectUsageRecordsByRecordId(recordId));
    }

    /**
     * 新增备件使用记录管理
     */
    //@PreAuthorize("@ss.hasPermi('system:records2:add')")
    //@Log(title= "备件使用记录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UsageRecords usageRecords) {
        return toAjax(usageRecordsService.insertUsageRecords(usageRecords));
    }

    /**
     * 修改备件使用记录管理
     */
    //@PreAuthorize("@ss.hasPermi('system:records2:edit')")
    //@Log(title= "备件使用记录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UsageRecords usageRecords) {
        return toAjax(usageRecordsService.updateUsageRecords(usageRecords));
    }

    /**
     * 删除备件使用记录管理
     */
    //@PreAuthorize("@ss.hasPermi('system:records2:remove')")
    //@Log(title= "备件使用记录管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds) {
        return toAjax(usageRecordsService.deleteUsageRecordsByRecordIds(recordIds));
    }
}
